#ifndef _H_SERVER
#define _H_SERVER

#include <cppthread.h>
#include <map>
#include <queue>
#include <string>
#include "sock.h"

using namespace std;

#define STATUS_NONE 0
#define STATUS_KILL 1

class message;

class client: public cpp_socket{

    protected:
        string name;
        unsigned int id;
        unsigned char status;

        bool op;

    public:
        client(cpp_socket*,unsigned int);
        ~client();

        void setName(string);
        void setStatus(unsigned char);

        unsigned int ID();
        unsigned char getStatus();
        string getName();

        int sendMes(message*);
        message* recvMes(unsigned short);

        void setOp(bool);
        bool getOp();

};

class clientList: public vector<client*>{

    protected:
        unsigned int id;

    public:
        clientList();
        ~clientList();

        client* createCli(cpp_socket*);
        clientList::iterator dropCli(unsigned int);
        clientList::iterator dropCli(clientList::iterator);

        clientList::iterator findCli(unsigned int);
        clientList::iterator findCli(string*);
        clientList::iterator findCli(char*);
        client* clFindCli(unsigned int);
        client* clFindCli(string*);
        client* clFindCli(char*);

        unsigned int ID();

};

class message{

    protected:
        client* sender;
        client* receiver;
        string content;

    public:
        message(string = "",client* = NULL, client* = NULL);

        void setSdr(client*);
        void setRcv(client*);
        void setStr(string);

        client* sdr();
        client* rcv();
        string ctt();

};

class messagequeue: public queue<message*>{

    protected:

    public:
        messagequeue();
        ~messagequeue();

        void drop();
        void flush();
        message* draw();

};

#endif
